<?php
require_once('class.internode.api.php');

class internode_api_cachefile extends internode_api
{
	var $cache_dir = './cache/';
	
	function __construct()
	{
		parent::__construct();
	}
	
	function fetch_data($post_extra=array())
	{
		$post = $post_extra;
		$post['username'] = $this->username; // ."@internode.on.net"
		$post['password'] = $this->password;
		$post['iso'] = 1;
		//$post['history'] = 1;
		
		$cachefile = $this->cache_dir . $this->username. '_' . sprintf("%x", crc32(serialize($post))) . '.tmp';
		
		if( file_exists($cachefile) && filemtime($cachefile) >= time() - (60 *60) )
			$data = @file_get_contents($cachefile);
		else
		{
			$data = parent::fetch_data($post_extra);
			file_put_contents($cachefile , $data );
		}
		return $data;
	}
}
